package com.zking.myservlet.category;

import com.zking.dao.CategoryDao;
import com.zking.entity.Category;

import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.IOException;
import java.util.List;

@WebServlet("/manage/categorySelectBig")
public class CategorySelectBig extends HttpServlet {
    protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
        //处理请求的编码，解决中文乱码
        request.setCharacterEncoding("utf-8");
        //处理响应的编码 ，解决中文乱码
        response.setContentType("text/html;charset=utf-8");

        System.out.println("CategorySelectBig===进来");

        //得到所有的大类  然后转发到product-add.jsp
        List<Category> bigList = CategoryDao.getBigCategory();

        bigList.add(new Category(-1, "新增大类", -1));
        bigList.sort((o1, o2) -> o1.getEpc_id() - o2.getEpc_id());

        request.setAttribute("bigList",bigList);
        request.getRequestDispatcher("productClass-add.jsp").forward(request, response);


    }

    protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
        doPost(request, response);
    }
}
